package com.coc.ofhibernate.controller;

import com.coc.ofhibernate.entity.database1.People;
import com.coc.ofhibernate.entity.database2.Person;
import com.coc.ofhibernate.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试双数据源
 */
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping (value = "/getUser1",method = RequestMethod.GET)
    public People getUser () {
        return testService.getUerById(1);
    }

    @RequestMapping (value = "/getUser2", method = RequestMethod.GET)
    public Person getUser2() {
        return testService.getUserById2(1);
    }

    @RequestMapping(value = "/save1", method = RequestMethod.GET)
    public void save1 (){
        People p = new People();
        p.setName("zhang");
        p.setAddress("SH");
        p.setPassword("123");

        testService.insertPeople(p);
    }

    @RequestMapping(value = "/save2", method = RequestMethod.GET)
    public void save2 (){
        Person person = new Person();
        person.setAddress("BJ");
        person.setName("wagn");
        person.setPassword("456");
        testService.insertPerson(person);
    }

}
